import type {
  SunnyMailConf,
  SunnyMailConfBO,
} from "@/types/sunnyMailConf/type";
import type { AxiosPromise } from "axios";
import request from "@/api/request";
import type { SunnyResponse } from "@/types/sunnyResp";

export function listSunnyMailConfApi(): AxiosPromise<SunnyMailConf[]> {
  return request({
    url: "/sunnyMail",
    method: "get",
  });
}

export function addSunnyMailConfApi(
  data: SunnyMailConf
): Promise<SunnyResponse> {
  return request({
    url: "/sunnyMail",
    method: "post",
    data,
  });
}

export function updateSunnyMailConfApi(
  data: SunnyMailConf
): Promise<SunnyResponse> {
  return request({
    url: "/sunnyMail",
    method: "put",
    data,
  });
}

export function deleteSunnyMailConfApi(id: number): Promise<SunnyResponse> {
  return request({
    url: "/sunnyMail/" + id,
    method: "delete",
  });
}

/**邮件发送方法 */
//发送测试邮件
export function sendTestMailApi(data: SunnyMailConf): Promise<SunnyResponse> {
  return request({
    url: "/sunnyMail/sendTest",
    method: "post",
    data,
  });
}

/**
 * 发送报告邮件，需要在请求体里携带resultId
 * @param data 携带resultId的业务对象
 * @returns
 */
export function sendReportMailApi(
  data: SunnyMailConfBO
): Promise<SunnyResponse> {
  return request({
    url: "/sunnyMail/sendReportMail",
    method: "post",
    data,
  });
}

/**
 * 发送报告邮件，resultId放到url路径上
 * @param data 携带resultId的业务对象
 * @returns
 */
export function sendReport(data: SunnyMailConfBO): Promise<SunnyResponse> {
  return request({
    url: "/sunnyMail/sendReport/" + data.resultId,
    method: "post",
    data,
  });
}
